package com.serv;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


// Not using annotations -- code in Web.xml 


public class ServEg1 extends HttpServlet {

	private static final long serialVersionUID = 1L;
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		
		response.setContentType("text/html");
		PrintWriter pw = response.getWriter();
		String userName = request.getParameter("name");
		HttpSession session=request.getSession();
		ServletContext context=request.getServletContext();
		
		if(userName!= "" && userName != null){
			session.setAttribute("savedUserName",userName);
			context.setAttribute("savedUserName",userName);
		}
		pw.println("Request : "+ userName);
		pw.println("Session Parameter :"+ session.getAttribute("savedUserName"));
		pw.println("ServletContext Parameter :"+ context.getAttribute("savedUserName"));
		
	}
	

}
